const imgModel = require('../models/img.js')

exports.cateList = async (req, res, next) => {
    try {
        const cates = await imgModel.getAllCates()
        res.status(200).json(cates)
    } catch (err) {
        next(err)
    }
}

exports.getImgs = async (req, res, next) => {
    try {
        const { cateid } = req.params
        const imgs = await imgModel.getImgsByCateId(cateid)
        res.status(200).json(imgs)
    } catch (err) {
        next(err)
    }
}

exports.getImg = async (req, res, next) => {
    try {
        const {id} = req.params
        const img = await imgModel.getImgById(id)
        res.status(200).json(img)
    } catch (err) {
        next(err)
    }
}

exports.getThumbs = async (req, res, next) => {
    try {
        const { imgid } = req.params
        const thumbs = await imgModel.getImgThumbs(imgid)
        res.status(200).json(thumbs)  
    } catch(err) {
        next(err)
    }
}